{extend name="public:base" /}
{block name="breadcrumbHeader"}
<h2>添加内容</h2>
{/block}
{block name="breadcrumb"}
<ol class="breadcrumb">
    <li class="breadcrumb-item">
        <a href="index.html">主页</a>
    </li>
    <li class="breadcrumb-item active">
        <strong>新增新闻</strong>
    </li>
</ol>
{/block}
{block name="js"}
<script type="text/javascript" src="__STATIC__/js/plugins/chosen/chosen.jquery.js"></script>
{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-content">
                    <form method="post" class="ajax-form" action="{:url('edit',['id'=>$row.id],'json')}">
                        <input name="uid" type="hidden">
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">标题</label>
                                <div class="col-sm-3">
                                    <input type="text" name="title" id="accountCheckIdentity"
                                           autocomplete="off"
                                           value="{$row.title}"
                                           class="form-control required-validate" placeholder="请输入标题">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
						<div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">排序</label>
                                <div class="col-sm-3">
                                    <input type="text" name="sort" value="{$row.sort}" class="form-control required-validate" placeholder="请输入序号,大的排前面">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">所属分类</label>
                                <div class="col-sm-3">
                                    <select class="form-control m-b" name="type_id">
                                        {volist name="new_classes" id="entity"}
                                        {eq name="$entity.id" value="$row.type_id"}
                                        <option value="{$entity.id}">{$entity.name}</option>
                                        {else/}
                                        <option value="{$entity.id}">{$entity.name}</option>
                                        {/eq}
                                        {/volist}
                                    </select>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
                        <div class="box-item">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">推荐</label>
                                <div class="col-sm-3">
                                    <div class="i-checks">
                                        <label> <input type="radio" value="1" name="recommend"
                                                       {eq name="row.recommend" value="1" }checked{/eq}><i></i> 否
                                        </label>
                                    </div>
                                    <div class="i-checks">
                                        <label> <input type="radio" value="2" name="recommend"
                                                       {eq name="row.recommend" value="2" }checked{/eq}><i></i> 是
                                        </label>
                                    </div>
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>
                        {eq name="row.recommend" value="2"}
                        <div class="box-item re_img_recommand">
                            {/eq}
                            {eq name="row.recommend" value="1"}
                            <div class="box-item re_img_recommand" style="display: none;">
                                {/eq}

                                <div class="form-group row">
                                    <label class="col-sm-1 col-form-label">推荐图片</label>
                                    <div class="col-sm-3">
                                        <div style="position: relative;cursor: pointer;"
                                             class="sealImg upload-file img-upload">
                                            <input type="hidden" class="required-validate" name="re_img"
                                                   placeholder="请上传图片"
                                                   value="{$row.reImgFile.id}">
                                            {if condition="$row.reImgFile"}
                                            <img class="img-upload-preview"
                                                 src="{$row.reImgFile.path}"
                                                 style="width: 100px;height: 100px;">
                                            {/if}
                                        </div>
                                        <input type="file" id="recommand_img" class="required-validate"
                                               style="display: none;" name="re_img_file">
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                            </div>
                            <div class="box-item">
                                <div class="form-group row">
                                    <label class="col-sm-1 col-form-label">新闻图片</label>
                                    <div class="col-sm-8">
                                        <div style="position: relative;cursor: pointer;"
                                             class="sealImg upload-file img-upload">
                                            <input type="hidden" class="required-validate" name="img"
                                                   value="{$row.imgFile.id}">
                                            {if condition="$row.imgFile"}
                                            <img class="img-upload-preview" src="{$row.imgFile.path}"
                                                 style="width: 100px;height: 100px;">
                                            {/if}
                                        </div>
                                        <input type="file" id="BannarImgId" style="display: none;" name="BannarImgId">
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                            </div>
                            <div class="box-item">
                                <div class="row">
                                    <label class="col-sm-1 col-form-label">新闻内容</label>
                                    <div class="col-lg-6">
                                        <div class="ibox ">
                                            <textarea id="editor_id">{$row.content}</textarea>
                                            <textarea name="content" data-editor="kindEditor"
                                                      style="display: none"></textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="hr-line-dashed"></div>
                            </div>
                            <div class="form-group row">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button type="button" class="btn btn-w-m btn-default back-page">返回</button>
                                    <button type="submit" class="btn btn-w-m btn-primary">提交</button>
                                </div>
                            </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

{/block}

{block name='js'}
<script type="text/javascript" src="__PLUG__/kindeditor/kindeditor-all.js"></script>
<script type="text/javascript" src="__ADMIN__/js/plugins/typehead/bootstrap3-typeahead.min.js"></script>
<script>
    initKindEditor('editor_id');
    $(document).ready(function () {
        $('.img-upload').on("click", function () {
            console.log("ssss")
            $(this).parent().find("input[type='file']").trigger("click");
        });
        $("input[name='recommend']").on("change", function (e) {
            console.log($(this).val());
            if (($(this).val() - 2) === 0) {
                console.log("2")
                $(".re_img_recommand").show();
            } else {
                console.log("1")
                $(".re_img_recommand").hide();
            }
        });
        $("input[id='BannarImgId']").on("change", function (e) {
            const _this = $(this).parent().find(".sealImg");
            var pic = $(this)[0].files[0];
            var formData = new FormData();
            var url = "{:url('UploadFile/uploadPicture',array('session_id'=>session_id()))}";
            formData.append('download', pic);
            $.ajax({
                url: url,
                type: "post",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.status === 1) {
                        //上传成功
                        var id = data.data[0].id;
                        var path = data.data[0].path;
                        _this.find('input[type="hidden"]').val(id);
                        _this.find('.img-upload-preview').remove();
                        _this.append('<img class="img-upload-preview" src="' + path + '" style="width: 100px;height: 100px;">');
                    } else {
                        layer.msg(data.info);
                    }
                }
            });
        });
        $("input[name='re_img_file']").on("change", function (e) {
            const _this = $(this).parent().find(".sealImg");
            var pic = $(this)[0].files[0];
            var formData = new FormData();
            var url = "{:url('UploadFile/uploadPicture',array('session_id'=>session_id()))}";
            formData.append('download', pic);
            $.ajax({
                url: url,
                type: "post",
                data: formData,
                cache: false,
                contentType: false,
                processData: false,
                success: function (data) {
                    if (data.status === 1) {
                        //上传成功
                        var id = data.data[0].id;
                        var path = data.data[0].path;
                        _this.find('input[type="hidden"]').val(id);
                        _this.find('.img-upload-preview').remove();
                        _this.append('<img class="img-upload-preview" src="' + path + '" style="width: 100px;height: 100px;">');
                    } else {
                        layer.msg(data.info);
                    }
                }
            });
        })
    });
</script>
{/block}
